import { getCs, getAllCs } from '@/api/putStorage/putStorageAdd'
import { getPstorageType } from '@/api/repertory/putstorage'
import { getAll, getstorageType } from '@/api/repertory/Storage'
import BoardService from '@/api/board/board'
import request from '@/utils/request'
import { getAllCustomer } from '@/api/project/customer'
import { getAllCgList } from '@/api/project/mstr'
// 厂商代码
const allCsOptions = {
  data() {
    return {
      allCsOptions: [],
    }
  },
  created: function () {
    getAllCs().then((response) => {
      this.allCsOptions = response.data.map((item) => {
        item.dictLabel = item.csmCs
        item.listClass = 'default'
        item.dictValue = item.csmCsdm
        return item
      })
    })
  },
}

// 厂商代码
const csOptions = {
  data() {
    return {
      csOptions: [],
    }
  },
  created: function () {
    getCs().then((response) => {
      this.csOptions = response.data
      for (let item of this.csOptions) {
        item.dictLabel = item.csmCs
        item.listClass = 'default'
        item.dictValue = item.csmCsdm
      }
    })
  },
}

// 单位
const unitFlagOptions = {
  data() {
    return {
      unitFlagOptions: [],
    }
  },
  created: function () {
    //单位
    this.getDicts('sys_unit').then((response) => {
      this.unitFlagOptions = response.data
    })
  },
}
//检验结果字典
const jyjgDict = {
  data() {
    return {
      jyjgDict: [
        {
          dictLabel: '允收',
          dictValue: 'OK',
          listClass: 'default',
        },
        {
          dictLabel: '拒收',
          dictValue: 'NG',
          listClass: 'default',
        },
        {
          dictLabel: '特采',
          dictValue: 'TC',
          listClass: 'default',
        },
      ],
    }
  },
}

const psTypeOptions = {
  data() {
    return {
      psTypeOptions: [],
    }
  },
  created: function () {
    //入库类型字典
    getPstorageType(0).then((response) => {
      this.psTypeOptions = response.data
      for (let i of this.psTypeOptions) {
        i.listClass = 'default'
      }
    })
  },
}

const allStorageOptions = {
  data() {
    return {
      allStorageOptions: [],
      allCwOptions: [],
    }
  },
  created: function () {
    getAll().then((response) => {
      this.allCwOptions = response.data.map((o) => {
        return { ...o, dictLabel: o.storageDefaultstorage, listClass: 'default', dictValue: o.storageId + '' }
      })

      this.allStorageOptions = response.data.map((o) => {
        return { ...o, dictLabel: o.storageName, listClass: 'default', dictValue: o.storageId + '' }
      })
    })
  },
}

const storageOptions = {
  data() {
    return {
      storageOptions: [],
      cWOptions: [],
    }
  },
  created: function () {
    getstorageType('0').then((response) => {
      this.cWOptions = response.data.map((o) => {
        return { ...o, dictLabel: o.storageDefaultstorage, listClass: 'default', dictValue: o.storageId + '' }
      })

      this.storageOptions = response.data.map((o) => {
        return { ...o, dictLabel: o.storageName, listClass: 'default', dictValue: o.storageId + '' }
      })
    })
  },
}

// 机台列表
const listJtmJtbh = {
  data() {
    return {
      listJtmJtbh: [],
      listJtm: [],
    }
  },
  created: function () {
    // 获取机台
    BoardService.getMachines().then((res) => {
      if (res.code === 200) {
        this.listJtm = res.data
        this.listJtmJtbh = res.data.map((a) => a.jtmJtbh)
      }
    })
  },
}
const portal = {
  data() {
    return {
      portalId: 'portal',
    }
  },
  created() {
    this.portalId += String(Math.round(Math.random() * 10000))
  },
}

const lbmMstrTree = {
  data() {
    return {
      lbmMstrTree: {},
    }
  },
  created() {
    request({
      url: '/project/lbm/lbmMstrTree',
      method: 'get',
    }).then((res) => {
      this.lbmMstrTree = res.data
    })
  },
}

const customerOptions = {
  data() {
    return {
      customerOptions: [],
    }
  },
  created: function () {
    getAllCustomer().then((response) => {
      response.data.map((i) => {
        i.dictLabel = i.cusName
        i.dictValue = i.cusId + ''
        i.listClass = 'default'
      })
      this.customerOptions = response.data
    })
  },
}
//得到采购属性
const bomCgsxOptions = {
  data() {
    return {
      bomCgsxOptions: [],
    }
  },
  created: function () {
    getAllCgList().then((response) => {
      this.bomCgsxOptions = response.data
      for (let i of this.bomCgsxOptions) {
        i.dictLabel = i.cgName
        i.dictValue = i.cgId + ''
        i.listClass = 'default'
      }
    })
  },
}

export default {
  allCsOptions,
  unitFlagOptions,
  jyjgDict,
  psTypeOptions,
  allStorageOptions,
  storageOptions,
  csOptions,
  listJtmJtbh,
  portal,
  lbmMstrTree,
  customerOptions,
  bomCgsxOptions,
}
